<!DOCTYPE html>
<html lang="en">
<script type="text/javascript" src="../resource/boot.js"></script>
<head>
    <meta charset="UTF-8">
    <title>logon</title>
</head>
<head>
    <title>Login</title>
    <style type="text/css">
        body
        {
            width:100%;height:100%;margin:0;overflow:hidden;
        }
    </style>
</head>
<body >
<div id="loginWindow" class="nui-window" title="用户登录" style="width:350px;height:165px;"
     showModal="true" showCloseButton="false"
>
    <div id="loginForm" style="padding:15px;padding-top:10px;">
        <table >
            <tr>
                <td style="width:60px;">帐号：</td>
                <td>
                    <input id="username" name="username" class="nui-textbox" value="" required="true" style="width:150px;"/>
                </td>
            </tr>
            <tr>
                <td style="width:60px;">密码：</td>
                <td>
                    <input id="pwd" name="pwd" class="nui-password" value="" requiredErrorText="密码不能为空" required="true" style="width:150px;" onenter="onLoginClick"/>
                    &nbsp;&nbsp;<a href=" " >忘记密码?</a>
                </td>
            </tr>
            <tr>
                <td></td>
                <td style="padding-top:5px;">
                    <a onclick="onLoginClick" class="nui-button" style="width:60px;">登录</a>
                    <a onclick="onResetClick" class="nui-button" style="width:60px;">重置</a>
                </td>
            </tr>
        </table>
    </div>

</div>

<script type="text/javascript">
    nui.parse();

    var loginWindow = nui.get("loginWindow");
    loginWindow.show();

    function onLoginClick(e) {
        var form = new nui.Form("#loginWindow");
        var username = form.getData().username;
        var pwd = form.getData().pwd;
        $.ajax({
            type: "POST",
            url: "http://localhost:8088/User/login",
            data: {
                username:username,
                pwd:pwd
            },
            success: function(result) {
                console.log(result.status);
                if (result.status == 200) {
                    nui.loading("登录成功，马上转到系统...", "登录成功");
                    setTimeout(function () {
                        window.location.href="http://localhost:8088/cadiExcelImpExport/template_nui/index.jsp";
                    }, 1500);
                } else {
                    alert(result.msg)
                }
            },
            error: function() {
                alert("服务器异常")
            }
        })
    }
    function onResetClick(e) {
        var form = new nui.Form("#loginWindow");
        form.clear();
    }
    /////////////////////////////////////
    function isEmail(s) {
        if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
            return true;
        else
            return false;
    }
    function onUserNameValidation(e) {
        if (e.isValid) {
            if (isEmail(e.value) == false) {
                e.errorText = "必须输入邮件地址";
                e.isValid = false;
            }
        }
    }
    function onPwdValidation(e) {
        if (e.isValid) {
            if (e.value.length < 5) {
                e.errorText = "密码不能少于5个字符";
                e.isValid = false;
            }
        }
    }
</script>

</body>
</html>